//
//  IntegralContentTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/20.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "IntegralContentTableViewCell.h"

@interface IntegralContentTableViewCell ()

@property (strong, nonatomic) UIImageView *bgIV;
@property (strong, nonatomic) UILabel *timeL;
@property (strong, nonatomic) UILabel *recordNumL;
@property (strong, nonatomic) UILabel *moneyL;
@property (strong, nonatomic) UILabel *balanceL;

@end

@implementation IntegralContentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgIV];
        [self.contentView addSubview:self.timeL];
        [self.contentView addSubview:self.recordNumL];
        [self.contentView addSubview:self.moneyL];
        [self.contentView addSubview:self.balanceL];
    }
    
    return self;
    
}

// 积分兑换列表
- (void)setRecordModel:(IntergralRecordModel *)recordModel {
    
    _recordModel = recordModel;
    
    self.timeL.text = recordModel.create_time;
    self.recordNumL.text = recordModel.doc;
    self.moneyL.text = [NSString stringWithFormat:@"+%@", recordModel.amount];
    self.balanceL.text = [NSString stringWithFormat:@"余额：%@", recordModel.usermoney];
    
}

// 积分明细
- (void)setIntegralModel:(IntergralRecordModel *)integralModel {
    
    _integralModel = integralModel;
    
    self.timeL.text = integralModel.create_time;
    self.recordNumL.text = integralModel.doc;
    
    if (self.type == 3 || self.type == 1) {
        // 获取积分
        self.moneyL.text = [NSString stringWithFormat:@"+%@", integralModel.money];
        
    }else {
        
        self.moneyL.text = [NSString stringWithFormat:@"-%@", integralModel.money];
    
    }
    
    self.balanceL.text = [NSString stringWithFormat:@"余额：%@", integralModel.user_bean];
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(weakSelf.contentView.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.width.mas_equalTo(jisuan(722));
        make.height.mas_equalTo(jisuan(134));
    }];
    [self.timeL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(weakSelf.bgIV.mas_bottom).with.offset(-Margin);
        make.left.mas_equalTo(weakSelf.bgIV.mas_left).with.offset(Margin);
    }];
    
    [self.moneyL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.bgIV.mas_right).with.offset(-Margin);
        make.top.mas_equalTo(weakSelf.bgIV.mas_top).with.offset(Margin);
    }];
    
    [self.balanceL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.bgIV.mas_right).with.offset(-Margin);
        make.centerY.mas_equalTo(weakSelf.timeL.mas_centerY);
    }];
    
    [self.recordNumL sizeToFit];
    [self.recordNumL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.bgIV.mas_left).with.offset(Margin);
        make.top.mas_equalTo(weakSelf.bgIV.mas_top).with.offset(Margin);
        make.right.mas_equalTo(weakSelf.moneyL.mas_left).with.offset(-jisuan(10));
    }];
}

#pragma mark -lazy
- (UIImageView *)bgIV {
    
    if (!_bgIV) {
        
        _bgIV = [[UIImageView alloc] init];
        _bgIV.contentMode = UIViewContentModeScaleAspectFit;
        _bgIV.image = [UIImage imageNamed:@"integralContentCellbg"];
    }
    return _bgIV;
}

- (UILabel *)timeL {
    
    if (!_timeL) {
        
        _timeL = [[UILabel alloc] init];
//        _timeL.text = @"2018.07.02 14:26:52";
        _timeL.textColor = Color999999;
        _timeL.font = Font(20);
        _timeL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _timeL;
}

- (UILabel *)recordNumL {
    
    if (!_recordNumL) {
        
        _recordNumL = [[UILabel alloc] init];
//        _recordNumL.text = @"字数字数字数字数字数字数字数字数字数字数";
        _recordNumL.textColor = Color333333;
        _recordNumL.font = Font(24);
        _recordNumL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _recordNumL;
}

- (UILabel *)moneyL {
    
    if (!_moneyL) {
        
        _moneyL = [[UILabel alloc] init];
//        _moneyL.text = @"+1.00";
        _moneyL.textColor = Color1f89ff;
        _moneyL.font = Font(32);
        _moneyL.textAlignment = NSTextAlignmentRight;
    }
    
    return _moneyL;
}

- (UILabel *)balanceL {
    
    if (!_balanceL) {
        
        _balanceL = [[UILabel alloc] init];
//        _balanceL.text = @"余额：17.89元";
        _balanceL.textColor = Color999999;
        _balanceL.font = Font(20);
        _balanceL.textAlignment = NSTextAlignmentRight;
    }
    
    return _balanceL;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
